package ${package_name}.controller;
import ${package_name}.service.I${table_name}Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import com.yonyou.f4.mvc.annotation.TxnConn;
import com.yonyou.f4.mvc.controller.BaseController;
import com.yonyou.dcs.common.bean.ElemBean;
/**
* 描述：${table_annotation}控制层
* @author ${author}
* @date ${date}
*/
@Controller
@TxnConn
@RequestMapping("/${table_name}")
public class ${table_name} extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(${table_name}Controller.class);

    @Autowired
    private I${table_name}Service ${table_name?uncap_first}Service;


    /**
	 * 
	 * @Title: getInfoByPage   
	 * @Description: 查询   
	 * @param queryParam
	 * @return      
	 * @return: PageInfoDto      
	 * @throws
	 */
	@RequestMapping(method=RequestMethod.GET)
	@ResponseBody
	public PageInfoDto getInfoByPage(@RequestParam Map<String,String> queryParam) {
	    ElemBean condition = new ElemBean(queryParam);
		return ${table_name?uncap_first}Service.getInfoByPage(queryParam);
	}

    /**
	 * 
	 * @Title: modifilyInfo   
	 * @Description: 修改
	 * @param dto      
	 * @return: void      
	 * @throws
	 */
	@RequestMapping(value="/modifilyInfo",method = RequestMethod.POST)
	@ResponseStatus(HttpStatus.OK)
	public void modifilyInfo(@RequestBody Map<String,String> queryParam) {
		ElemBean condition = new ElemBean(queryParam);
		${table_name?uncap_first}Service.modifilyInfo(condition);
		
	}
	
	/**
	 * 
	 * @Title: getActivityPlanCreateInfoByPlanId   
	 * @Description: 根据id查询数据 
	 * @return      
	 * @return: Map      
	 * @throws
	 */
	@RequestMapping(value = "/{id}",method = RequestMethod.GET)
	@ResponseBody
	public Map getInfoById(@PathVariable String id) {
		
		return ${table_name?uncap_first}Service.getInfoById(id);
	}

    /**
     * 
     * @Title: getAttachmentPageInfo   
     * @Description: 传入表名，主键id。就可以新增和这个id关联的附件
     * @param dealerId
     * @return      
     * @return: PageInfoDto      
     * @throws
     */
	@RequestMapping(value = "/addAttachment/{tableName}/{businessId}" , method = RequestMethod.POST)
	@ResponseBody
	public void addAttachment(@RequestBody Map<String,String> map,@PathVariable String tableName,@PathVariable String businessId){
		
		ElemBean queryParam = new ElemBean(map);
		if(queryParam.get("dmsFileIds")!=null&&!"##@".equals(queryParam.get("dmsFileIds").toString())){
    		
			String[] dmsFileIds = queryParam.get("dmsFileIds").toString().split(",;");
    		for(String dmsFileId : dmsFileIds){
    			
				String[] name = dmsFileId.substring(3,dmsFileId.length()).split("#@#");
				
				//1.新增附件数据
				TmAttachmentPo attachmentPO = new TmAttachmentPo();
				attachmentPO.set("BUSINESS_ID",businessId);
				attachmentPO.set("NAME", name[1]);
				attachmentPO.set("URL", name[0]);
				attachmentPO.set("FILE_ID", name[0].substring(name[0].lastIndexOf("/")+1));
				attachmentPO.set("VALID_STATUS", Constant.STATUS_ENABLE);
				attachmentPO.set("ATTACHMENT_TYPE",tableName);
				attachmentPO.saveIt();
				
			}
		}
	}
	
	/**
     * 
     * @Title: getAttachmentPageInfo   
     * @Description: 查询附件列表  
     * @param dealerId
     * @return      
     * @return: PageInfoDto      
     * @throws
     */
    @RequestMapping(value = "/getAttachmentPageInfo/{attachmentId}" , method = RequestMethod.GET)
    @ResponseBody
    public PageInfoDto getAttachmentPageInfo(@PathVariable String attachmentId) {
    	
    	return ${table_name?uncap_first}Service.getAttachmentPageInfo(attachmentId);
    }
    
    /**
     * 
     * @Title: getAttachmentPageInfo   
     * @Description: 删除附件  
     * @param dealerId
     * @return      
     * @return: PageInfoDto      
     * @throws
     */
    @RequestMapping(value = "/deleteAttachMentInfoById/{attachmentId}" , method = RequestMethod.DELETE)
    @ResponseBody
    public void deleteAttachMentInfoById(@PathVariable String attachmentId) {
    	${table_name?uncap_first}Service.deleteAttachMentInfoById(attachmentId);
    
    }

}